<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="stylesheet" type="text/css" href="css/common.css"/>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>
	<script src="js/jquery.js"></script>
	<script type="text/javascript" src="js/public.js"></script>
    <script>
        window.onload = function (){
        	var token = sessionStorage.getItem("token");
        	if(token == null){
        		window.location.href = "/shop/login.html";
        	}
        	var consumerName = sessionStorage.getItem("consumerName");
        	var role = "店长";
        	if(sessionStorage.getItem("role") != "1"){
        					  role = "店员";
        	}
        	document.getElementById("manager_name").innerText = role+":"+consumerName;
        }
		
		function newCategory(){
			const data = {
				categoryName:document.getElementById("category").value
			}
			fetch("http://localhost:8080/category/add",{method: 'POST',
				headers: {  
					'Content-Type': 'application/json',
					'token': sessionStorage.getItem("token"), 
					},  
				body:JSON.stringify(data),
				})
			
			    .then(response => {
			        // 确保服务器返回的是JSON数据
			        if (!response.ok) {
			            throw new Error('Failed to fetch data');
			        }
					return response.text();
					
			    })
				.then(data =>{
					let isSuccess = data.toLowerCase() === 'true';  
					        if (isSuccess) {  
					            alert("商品分类添加成功");  
					        } else {  
					            alert("商品分类添加失败");  
					        }  
				})
			    .catch(error => {
			        // 处理错误
			        console.error('Error:', error);
			    });
		}
    </script>
</head>
<body>
<div class="topbar-wrap white">
    <div class="topbar-inner clearfix">
        <div class="topbar-logo-wrap clearfix">
            <h1 class="topbar-logo none"><a href="admin.html" class="navbar-brand">后台管理</a></h1>
            <ul class="navbar-list clearfix">
                <li><a class="on" href="admin.html">首页</a></li>
                <li><a href="admin.html" target="_blank">网站首页</a></li>
            </ul>
        </div>
        <div class="top-info-wrap">
            <ul class="top-info-list clearfix">
                <li><a href="store.html" id="manager_name">管理员</a></li>
                <li><a href="password.html">修改密码</a></li>
                <li><a href="#" onclick="logout()">退出</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="container clearfix">
    <div class="sidebar-wrap">
        <div class="sidebar-title">
            <h1>菜单</h1>
        </div>
        <div class="sidebar-content">
            <ul class="sidebar-list">
                <li>
                    <a href="#"><i class="icon-font">&#xe003;</i>常用操作</a>
                    <ul class="sub-menu">
                        <li><a href="product.html"><i class="icon-font">&#xe008;</i>商品管理</a></li>
                        <li><a href="order.html"><i class="icon-font">&#xe005;</i>订单管理</a></li>
						<li><a href="insert.html"><i class="icon-font">&#xe005;</i>商品新增</a></li>
						<li><a href="category.html"><i class="icon-font">&#xe005;</i>类型管理</a></li>
						
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="icon-font">&#xe018;</i>系统管理</a>
                    <ul class="sub-menu">
                        <li><a href="store.html"><i class="icon-font">&#xe017;</i>店铺信息设置</a></li>
						<li><a href="manager.html"><i class="icon-font">&#xe017;</i>个人信息设置</a></li>
						<li><a href="members.html"><i class="icon-font">&#xe017;</i>店铺成员信息</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="admin.html">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="/jscss/admin/design/">商品管理</a><span class="crumb-step">&gt;</span><span>新增类型</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                        <tbody>
                            <tr>
                                <th><i class="require-red">*</i>分类名称：</th>
                                <td>
                                    <input class="common-text required" id="category" name="productName" size="50" value="" type="text">
                                </td>
                            </tr>
							<tr>
								<td colspan=2 style="text-align: center;"><input type="button" value="新增" onclick="newCategory()"/></td>
							</tr>
                        </tbody></table>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
</body>
</html>